package com.sun.designpatternsdemo.singleton

import android.os.Bundle
import com.sun.designpatternsdemo.base.BaseActivity
import com.sun.designpatternsdemo.R
import com.sun.designpatternsdemo.databinding.ActivitySingletonBinding
import com.sun.designpatternsdemo.singleton.bean.*

class SingletonActivity : BaseActivity<ActivitySingletonBinding>() {
    override fun layoutId(): Int =R.layout.activity_singleton

    override fun initView(savedInstanceState: Bundle?) {
        title = "单例模式"
        mDataBind.apply {
            btEhan.setOnClickListener {//饿汉式（可用）
                val instance: SingletonEHan = SingletonEHan.getInstance()
            }
            btLanhan.setOnClickListener { // 懒汉式[双重校验锁 推荐用]
                val instance = SingletonLanHan.getSingletonLanHanFour()
            }
            btInclass.setOnClickListener { //内部类[推荐用]
                val instance = SingletonIn.getSingletonIn()
            }
            btEnum.setOnClickListener { // 枚举[推荐用]
                val instance = SingletonEnum.instance.whateverMethod()
            }
            btDc.setOnClickListener {
                val instance = SingletonDC.getInstance()
            }
        }
    }
}